<template>
	<!-- 系统设置模块-删除个险数据-->
	<div class="fillcontain">
		<!-- 标题 -->
		<div class="fastQuery">
			<el-row>
				<el-col :span="5" class="common-box">
					<el-col :span="6" class="common-lab">
						<label class="labelName">受理号</label>
					</el-col>
					<el-col :span="14">
						<el-input clearable v-model="searchParams.busiNO" placeholder=""></el-input>
					</el-col>
				</el-col>
				<el-col :span="5" class="common-box">
					<el-col :span="6" class="common-lab">
						<label class="labelName">保单号</label>
					</el-col>
					<el-col :span="14">
						<el-input clearable v-model="searchParams.policyNO" placeholder=""></el-input>
					</el-col>
				</el-col>
				<el-col :span="6" class="common-box">
					<el-col :span="7" class="common-lab">
						<label class="labelName">核决时间（开始）</label>
					</el-col>
					<el-col :span="14">
						<el-date-picker @change="clearTimeSetDefault" v-model="searchParams.begintime" format="yyyy-MM-dd" value-format="yyyy-MM-dd"
						 type="date">
						</el-date-picker>
					</el-col>
				</el-col>
				<el-col :span="6" class="common-box">
					<el-col :span="7" class="common-lab">
						<label class="labelName">核决时间（结束）</label>
					</el-col>
					<el-col :span="14">
						<el-date-picker @change="clearTimeSetDefault" v-model="searchParams.endtime" format="yyyy-MM-dd" value-format="yyyy-MM-dd"
						 type="date">
						</el-date-picker>
					</el-col>
				</el-col>
			</el-row>
			<el-row>
				<el-col :span="4" class="text_center" style="float: right;margin-top: 0.625rem;">
					<el-button type="primary" icon="el-icon-search" @click="search"></el-button>
					<el-button type="primary" plain icon="el-icon-refresh" @click="resetSearch"></el-button>
				</el-col>
			</el-row>
		</div>
		<div class="contain">
			<!-- 操作按钮 -->

			<el-row class="pb10">
				<el-col :span="3">
					<el-button type="danger" plain @click="resetPrint('Y')">重置列印（Y）</el-button>
				</el-col>
				<el-col :span="3">
					<el-button type="danger" plain @click="resetPrint('N')">重置列印（N）</el-button>
				</el-col>
				<el-col :span="1.9">
					<el-upload ref="upload" :action="actionUrl" :show-file-list="false" :on-success="onSuccess" :on-error="onError"
					 :format="['xls']" :headers="myHeaders" :on-format-error="handleFormatError" accept="application/vnd.openxmlformats-officedocument.spreadsheetml.sheet,application/vnd.ms-excel">
						<el-button size="mini" type="danger" :disabled="!enabledUploadBtn" :icon="uploadBtnIcon">{{btnText}}</el-button>
					</el-upload>
				</el-col>
			</el-row>
			<div class="table_container">
				<el-table :data="tableData" highlight-current-row header-cell-class-name="table-header-class" ref="multipleTable"
				 @selection-change="handleSelectionChange" style="width:100%">
					<el-table-column type="selection"></el-table-column>
					<el-table-column property="busiNo" label="受理号" align='center'></el-table-column>
					<el-table-column property="policyNo" label="保单号" align='center'></el-table-column>
					<el-table-column property="productType" label="类型" align='center'></el-table-column>
					<el-table-column property="docTyp" label="影像类型" align='center'></el-table-column>
					<el-table-column width="100" label="是否列印" align='center'>
						<template slot-scope="scope">
							<span v-if="scope.row.isPrint == 0">N</span>
							<span v-if="scope.row.isPrint == 1">Y</span>
						</template>
					</el-table-column>
					<el-table-column fixed="right" label="操作" align='center'>
						<template slot-scope="scope">
							<span class="operationIcon" @click="modifyData(scope.row)">
								<!-- 删除操作 -->
								<el-tooltip class="item" effect="light" content="修改列印状态" placement="">
									<i class="el-icon-setting"></i>
								</el-tooltip>
							</span>
						</template>
					</el-table-column>
					<el-table-column property="procflg" v-if="false"></el-table-column>
				</el-table>
				<!-- <el-row>
					<el-col :span="24">
						<div class="pagination">
							<el-pagination background v-if='paginations.total > 0' :page-sizes="paginations.pageSizes" :page-size="paginations.pageSize"
							 :layout="paginations.layout" :total="paginations.total" :current-page='paginations.pageIndex' @current-change='handleCurrentChange'
							 @size-change='handleSizeChange'>
							</el-pagination>
						</div>
					</el-col>
				</el-row> -->
			</div>
		</div>


	</div>
</template>
<script>
	import TaskConstants, {
		call
	} from "@/api/taskManager/common"
	import constant from "@/utils/constant";
	import {
		getToken
	} from '@/utils/auth' // 验权(从cookie中获取)
	import {
		Message,
		MessageBox
	} from 'element-ui';
	export default {
		data() {
			return {
				multipleSelection: [],
				emptySearchParams: {}, //空的查询
				begintime: '',
				endtime: '',
				btnText: '批量置为Y',
				enabledUploadBtn: true,
				uploadBtnIcon: "el-icon-upload2",
				//文件上传路由
				actionUrl: TaskConstants.apis.importModify,
				myHeaders: {
					'Authorization': getToken(constant.TOKEN) || ''
				},
				searchParams: {
					busiNO: '',
					policyNO: '',
					begintime: '',
					endtime: '',
					pageNumber: '',
					pageSize: ''
				},
				drawer: false,
				loading: false,
				userInfo: {},
				tableData: [],
				//需要给分页组件传的信息
				paginations: {
					total: 0, // 总数
					pageIndex: 1, // 当前位于哪页
					pageSize: 100, // 1页显示多少条
					pageSizes: [5, 10, 15, 20], //每页显示多少条
					layout: "total, sizes, prev, pager, next, jumper", // 翻页属性
				},

			}
		},
		created() {
			this.emptySearchParams = JSON.parse(JSON.stringify(this.searchParams));
			this.userInfo = JSON.parse(localStorage.getItem(getToken('token'))).userKeyInfo;
		},
		mounted() {},
		methods: {
			onSuccess(response, file, fileList) {
				if (response.resultCode == constant.SUCCESS) {
					this.$message({
						message: '处理成功！',
						type: 'success'
					});
				} else {
					this.$message({
						message: '处理失败！',
						type: 'error'
					});
				}
				this.enabledUploadBtn = true;
				this.uploadBtnIcon = 'el-icon-upload2';
				this.btnText = '批量置为Y';

			},
			onError(err, file, fileList) {
				this.enabledUploadBtn = true;
				this.uploadBtnIcon = 'el-icon-upload2';
				this.btnText = '批量置为Y';
				this.$message({
					message: '处理失败！',
					type: 'error'
				});
			},
			beforeUpload(file) {
				this.enabledUploadBtn = false;
				this.uploadBtnIcon = 'el-icon-loading';
				this.btnText = '正在重置';
			},
			handleFormatError(file) {
				this.$Notice.warning({
					title: '文件格式不正确',
					desc: '文件 ' + file.name + ' 格式不正确，请上传.xls,.xlsx文件。'
				});
			},
			handleClose(done) {
				this.drawer = false
				this.loading = false
			},
			resetSearch() {
				this.searchParams = JSON.parse(JSON.stringify(this.emptySearchParams));
			},
			handleSelectionChange(val) {
				console.log(val)
				this.multipleSelection = val;
			},
			clearTimeSetDefault(val) {
				if (val == null) {
					val = '';
				}
			},
			search() {
				if (!this.searchParams.busiNO && !this.searchParams.policyNO && !this.searchParams.begintime) {
					this.$message.error('请输入查询条件！');
					return false;
				}
				if (this.searchParams.begintime && this.searchParams.endtime) {
					let oDate1 = new Date(this.searchParams.begintime);
					let oDate2 = new Date(this.searchParams.endtime);
					if (oDate1.getTime() > oDate2.getTime()) {
						this.$message.error("起始时间不能大于结束时间！");
						return;
					}
				}
				this.paginations.total = 0;
				this.tableData = [];
				this.searchParams.pageNumber = this.paginations.pageIndex;
				this.searchParams.pageSize = this.paginations.pageSize;
				this.$store.dispatch('loading/CHNAGE_SUBLOADING', true);
				this.searchParams.pageNumber = this.paginations.pageIndex;
				this.searchParams.pageSize = this.paginations.pageSize;
				call(TaskConstants.apis.printList, this.searchParams, "post").then(res => {
					if (res.resultCode == constant.SUCCESS && res.data && res.data.list.length > 0) {
						let pageData = res.data;
						this.tableData = pageData.list;
						this.paginations.total = pageData.total;
						this.paginations.currentPage = pageData.pageNum;
					}
					this.$store.dispatch('loading/CHNAGE_SUBLOADING', false);
				}).catch(err => {
					console.log(err);
					this.$store.dispatch('loading/CHNAGE_SUBLOADING', false);
				})
			},
			resetPrint(flag) {
				let all = [];
				let param = {};
				if ("N" == flag) {
					flag = "0"
				} else {
					flag = "1"
				}
				this.multipleSelection.forEach(ite => {
					let item = {};
					item = ite;
					item["isPrint"] = flag;
					item["stype"] = "modify";
					all.push(item);
				});
				param["userId"] = this.userInfo.account;
				param["reqBody"] = all;
				MessageBox.confirm("是否更改所选择的列的影像列印状态", '提示', {
					confirmButtonText: '确定',
					cancelButtonText: '取消',
					type: 'warning'
				}).then(() => {
					this.$store.dispatch('loading/CHNAGE_SUBLOADING', true);
					call(TaskConstants.apis.imageModify, param, "post").then(res => {
						if (res.resultCode == constant.SUCCESS) {
							this.$store.dispatch('loading/CHNAGE_SUBLOADING', false);
							this.$message({
								message: '修改成功！',
								type: 'success'
							});
							this.search()
						} else {
							this.$store.dispatch('loading/CHNAGE_SUBLOADING', false);
						}
					}).catch(error => {
						this.$store.dispatch('loading/CHNAGE_SUBLOADING', false);
					})
				});
			},
			modifyData(row) {
				let isPrint = row.isPrint
				let tmp = isPrint;
				if (isPrint == "1") {
					tmp = "0"
				}
				if (isPrint == "0") {
					tmp = "1";
				}
				let param = {};
				let reqBody = {};
				for (let key in row) {
					reqBody[key] = row[key]
				}
				reqBody["isPrint"] = tmp;
				reqBody["stype"] = "modify";
				param["userId"] = this.userInfo.account;
				param["reqBody"] = reqBody;
				MessageBox.confirm("是否更改" + row.busiNo + "的列印状态", '提示', {
					confirmButtonText: '确定',
					cancelButtonText: '取消',
					type: 'warning'
				}).then(() => {
					this.$store.dispatch('loading/CHNAGE_SUBLOADING', true);
					call(TaskConstants.apis.imageModifyOne, param, "post").then(res => {
						if (res.resultCode == constant.SUCCESS) {
							this.$store.dispatch('loading/CHNAGE_SUBLOADING', false);
							if ("" == res) {
								this.$message({
									message: '修改失败！',
									type: 'error'
								});
							} else {
								this.$message({
									message: '修改成功！',
									type: 'success'
								});
							}
							this.search()
						} else {
							this.$store.dispatch('loading/CHNAGE_SUBLOADING', false);
							this.$message({
								message: '修改失败！',
								type: 'error'
							});
						}

					}).catch(error => {
						this.$store.dispatch('loading/CHNAGE_SUBLOADING', false);
					})
				});
			},
			resetSearch() {
				this.searchParams = JSON.parse(JSON.stringify(this.emptySearchParams));
			},
			// 每页多少条切换
			handleSizeChange(pageSize) {
				this.paginations.pageIndex = 1;
				this.paginations.pageSize = pageSize;
				this.search();
			},
			// 上下分页
			handleCurrentChange(page) {
				this.paginations.pageIndex = page;
				this.search();
			},

		},
		computed: {},
		watch: {
			begintime(newVal, oldVal) {
				if (newVal == null) {
					this.searchParams.begintime = '';
				} else {
					this.searchParams.begintime = newVal;
				}
			}
		}
	}
</script>
<style lang="less" scoped>
	.fillcontain {
		padding-bottom: 0;

		.fastQuery {
			padding: 15px 20px 10px 20px;
			background: #fff;

			.fastQuery_title {
				color: #666;
				padding: 6px 0px;
			}
		}
	}

	.contain {
		background: #fff;
		padding: 10px;
		margin-bottom: 20px;
	}

	.pagination {
		padding: 10px 20px;
		text-align: right;
	}
</style>
